package com.visionblue.business.ship.page.dialog

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.view.inputmethod.EditorInfo
import com.visionblue.business.ship.R
import com.visionblue.business.ship.page.MainActivity
import com.visionblue.business.ship.page.register.RegisterActivity
import com.visionblue.business.ship.util.DeviceUtil
import com.visionblue.business.ship.util.toast
import kotlinx.android.synthetic.main.dialog_device_pwd.*

/**
 * @author: xlh
 * @date: 2020-06-07 10:19 PM
 * @desc:
 */
class DevicePwdDialog(context: Activity) : Dialog(context, R.style.blurry_slide_dialog) {

    init {
        setContentView(R.layout.dialog_device_pwd)

        etPwd.setOnEditorActionListener { _, actionId, _ ->
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                checkPwd(context)
                return@setOnEditorActionListener true
            }
            return@setOnEditorActionListener false
        }

        tvSure.setOnClickListener {
            checkPwd(context)
        }

        tvBack.setOnClickListener {
            dismiss()
        }

    }

    private fun checkPwd(context: Activity) {
        if (etPwd.text.toString() == "888888") {
            RegisterActivity.start(context, MainActivity.CODE_REGISTER)
            dismiss()
        } else {
            toast { "密码错误" }
        }
    }
}